﻿<script type="text/javascript" src='@Url.Content("~/Content/jquery-ui-1.10.2.custom/js/jquery-1.9.1.js")'></script>
<script type="text/javascript" src='@Url.Content("~/Content/jquery-ui-1.10.2.custom/js/jquery-ui-1.10.2.custom.js")'></script>
<script type="text/javascript" src='@Url.Content("~/Content/js/jquery.ui.datepicker-pt-BR.js")'></script>
<script type="text/javascript" src='@Url.Content("~/Content/js/jquery.meio.mask.js")'></script>
<script type="text/javascript" src='@Url.Content("~/Content/js/jquery.price_format.1.8.min.js")'></script>
<script type="text/javascript">

    $("div.validation-summary-errors").click(function () {
        $("div.validation-summary-errors").fadeOut("slow");
    });

    $(document).ready(function () {

        $.datepicker.setDefaults($.datepicker.regional[""]);
        $(".datepicker").datepicker($.datepicker.regional["pt-BR"]);
        $(".datepicker").datepicker({
            inline: true,
            changeMonth: true,
            changeYear: true
        });

        jQuery(function ($) {
            $('.decimal').setMask("decimal");
            $('.datepicker').setMask("date");
            $('.centena').setMask("centena");
        });
    });

    function MoneyToFloat(valor) {
        return parseFloat(getNum(valor.replace(/\s/g, "").replace(".", "").replace(".", "").replace(".", "").replace(".", "").replace(",", ".")));
    }

    function getNum(num) {
        if (num == '' || (num + 0) == 0)
            num = "0";
        return num;
    }

    function parseMoney(num) {
        var x = 0;

        num = getNum(num);

        if (num < 0) {
            num = Math.abs(num);
            x = 1;
        }
        if (isNaN(num))
            num = "0";

        cents = Math.floor((num * 100 + 0.5) % 100);
        num = Math.floor((num * 100 + 0.5) / 100).toString();

        if (cents < 10)
            cents = "0" + cents;

        for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++)
            num = num.substring(0, num.length - (4 * i + 3)) + '.' + num.substring(num.length - (4 * i + 3));

        ret = num + ',' + cents;

        if (x == 1)
            ret = ' - ' + ret;

        return ret;
    }

</script>
